package com.siqi.hr.system.common.sql;

import com.siqi.hr.system.common.utils.EnumUtils;
import com.siqi.hr.system.common.utils.intf.BaseEnum;

/**
 * 拼sql的辅助类的类型
 */
public class SFieldType {
    //类型名称
    private String name;
    //Java表达式
    private String javaRegular;
    //数据库类型
    private DatabaseType databaseType;
    //中文名
    private String inchinese;

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getJavaRegular() {
        return this.javaRegular;
    }

    public void setJavaRegular(String javaRegular) {
        this.javaRegular = javaRegular;
    }

    public DatabaseType getDatabaseType() {
        return this.databaseType;
    }

    public void setDatabaseType(DatabaseType databaseType) {
        this.databaseType = databaseType;
    }

    public void setDatabaseType(String databaseType) {
        this.databaseType = ((DatabaseType) EnumUtils.getByCode(databaseType, DatabaseType.class));
    }

    public String getInchinese() {
        return this.inchinese;
    }

    public void setInchinese(String inchinese) {
        this.inchinese = inchinese;
    }

    public String toString() {
        return "(" + this.inchinese + ":" + this.name + ")";
    }

    public static void main(String[] args) {
        System.out.println(EnumUtils.getByCode("int", DatabaseType.class));
    }

    public SFieldType(String name, String javaRegular, DatabaseType databaseType, String inchinese) {
        this.name = name;
        this.javaRegular = javaRegular;
        this.databaseType = databaseType;
        this.inchinese = inchinese;
    }

    public SFieldType() {
    }

    public static enum DatabaseType implements IDatabaseType {
        INT("int", false), LONG("long", false), VARCHAR("varchar", true), DATETIME("datetime", true),
        TIMESTAMP("timestamp", true), DATE("date",true), TEXT("text", false),MEDIUMTEXT("mediumtext", false),
        BIT("bit", false),DECIMAL("decimal", true);

        private String databaseTYpe;
        private boolean needQuotation;

        private DatabaseType(String databaseTYpe, boolean needQuotation) {
            this.databaseTYpe = databaseTYpe;
            this.needQuotation = needQuotation;
        }

        public String getDataBaseType() {
            return this.databaseTYpe;
        }

        public boolean needSingleQuotationMarks() {
            return this.needQuotation;
        }

        public String getCode() {
            return this.databaseTYpe;
        }

        public String getDesc() {
            return "";
        }
    }

    private static abstract interface IDatabaseType extends BaseEnum<String> {
        public abstract String getDataBaseType();

        public abstract boolean needSingleQuotationMarks();
    }
}
